package org.wei.p2p.consumer.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @author wei
 * @date 2022/2/22 21:45
 */
public class ConsumerGeneratorCode {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/p2p_consumer", "root", "xuanniao")
                .globalConfig(builder -> {
                    builder.author("wei") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .disableOpenDir()
                            .outputDir("D:\\code\\IdeaProjects\\p2p\\p2p-consumer-service\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("org.wei.p2p.consumer") // 设置父包名
//                            .moduleName("system") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\code\\IdeaProjects\\p2p\\p2p-consumer-service\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("consumer") // 设置需要生成的表名
//                            .addTablePrefix("sys_") // 设置过滤表前缀
                         .entityBuilder()
                            .enableChainModel()
                            .enableLombok()
                         .controllerBuilder()
                            .enableRestStyle()
                         .mapperBuilder()
                            .enableMapperAnnotation()
                            .enableBaseResultMap()
                            .enableBaseColumnList();
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateConfig(builder -> {
                    builder.entity("/templates/entity.java")
                            .service("/templates/service.java")
                            .serviceImpl("/templates/serviceImpl.java")
                            .mapper("/templates/mapper.java")
                            .xml("/templates/mapper.xml")
                            .controller("/templates/controller.java");
                })
                .execute();

    }
}
